<?php
class FileAction extends Action
{ 
public function down()
{
	$orginalname=$_GET["name"];
	$level=$_GET["level"];
	if ($orginalname=='')
	{
		echo "<script>alert('无文件名!');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
	}
	$file=D("file");
	$condition['orginalname'] = $orginalname;
	$condition['level']= $level;
	$list=$file->where($condition)->select();
	$savename=iconv("UTF-8", "GB2312", $list[0]['path']);
	//$savename=iconv("UTF-8", "GB2312", "C:/wamp/www/ivycapital/Public/example/uploads/殷三三/啊啊.txt");
	$showname=iconv("UTF-8", "GB2312", $list[0]['orginalname']);
	//$showname=$list[0]['orginalname'];
	import('@.ORG.Http'); 
    Http::download($savename,$showname); 
}

public function downall()
{
	$project=$_GET['project'];
	$level=$_GET['level'];
	//$level=$_GET['level'];
	if ($project==''){echo "<script>alert('无项目名!');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";}
	//$file=D("file");
	//$condition['project'] = $project;
	//$list=$file->where($condition)->select();
	
	$con = mysql_connect("localhost","root","");
	if (!$con)
 	 {
 	 die('Could not connect: ' . mysql_error());
	  }
	mysql_select_db("test", $con);
	$sql="select * from file where project='".$project."' and level='".$level."'";
	$result=mysql_query($sql,$con);
	
	
	$zip=new ZipArchive();
	
	//$zipath1='C:/wamp/www/ivycapital/Public/example/uploads/'.$project.'/'.$level.'/'.$project.'-'.$level.'.zip';
	$zipath1='C:/wamp/www/ivycapital/Public/uploads/'.$project.'/'.$level.'/'.$project.'-'.$level.'.zip';
	$zipath=iconv("UTF-8", "GB2312",$zipath1);
	
	
	$zipname1=$project.'-'.$level.'.zip';
	$zipname=iconv("UTF-8", "GB2312", $zipname1);
	$res=$zip->open($zipath,ZipArchive::OVERWRITE);
	
	
	
	
	if ($res==TRUE)
	{	
    while ($row= mysql_fetch_array($result))
	{
		//这里将文件打包成zip格式
		$realpath=iconv("UTF-8","GB2312",$row['path']);
		$name=iconv("UTF-8", "GB2312", $row['orginalname']);
		//$name=$row['orginalname'];
		$zip->addFile($realpath,$name);		
	}
	$zip->close();
	import('@.ORG.Http');
	Http::download($zipath,$zipname);
	}
	else
	{
		echo "zip文件创建失败";
	}
}
}
?>